package com.example.todolist.mapper;

import com.example.todolist.entity.Habit;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HabitMapper {
    @Insert("insert into habit(userId,habitName,beginDate,habitId,lastDays)VALUE(#{userId},#{habitName},#{beginDate},#{habitId},#{lastDays})")
    Integer insertHabit(Habit habit);
    @Select("select * from habit where userId=#{userId} AND habitId=#{habitId}")
    Habit getHabit(Integer userId,Integer habitId);

    @Select("select ${weekDay} from habit where userId=#{userId} AND habitId=#{habitId}")
    Integer getWeekStatus(Integer userId,Integer habitId,String weekDay);
    @Update("update habit set ${weekDay} = #{status} where userId=#{userId} AND habitId=#{habitId}")
    Integer setForHabit(Integer userId,Integer habitId,String weekDay,Integer status);

    @Select("select habitId from habit where userId=#{userId} AND habitName=#{habitName}")
    Integer getHabitId(Integer userId,String habitName);

    @Select("select * from habit where userId=#{userId}")
    List<Habit> getAllHabit(Integer userId);

    @Delete("delete from habit where userId=#{userId} AND habitId=#{habitId}")
    void deleteHabit(Integer userId,Integer habitId);

    @Update("update habit set lastDays=#{lastDays} where userId=#{userId} AND habitId=#{habitId}")
    void setLastDays(Integer userId, Integer habitId, Integer lastDays);

    @Select("select habitName from habit where userId=#{userId} AND ${weekDay}=1")
    List<String> getLastDayHabit(Integer userId,String weekDay);
}
